<?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <xsl:output encoding="utf-8" method="text"/>
  <xsl:strip-space elements="*"/>
  
  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="collection">
         <xsl:apply-templates select="collection"/>
      </xsl:when>
      <xsl:otherwise>
        Warning: The metadata of this object is not set properly. Or it might be missing or destoried.
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="collection">  
    <xsl:choose>
      <xsl:when test="marc:record">
         <xsl:apply-templates select="marc:record"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="marc:record">
    <xsl:choose>      
      <xsl:when test="marc:datafield[@tag='655' and @ind2='7']">
          <xsl:variable name="type" select="marc:datafield[@tag='655' and @ind2='7']/marc:subfield[@code='a']"/>
          <xsl:variable name="book">Book</xsl:variable>
          <xsl:variable name="book_chapter">Book Chapter</xsl:variable>
          <xsl:variable name="conference_paper">Conference Paper</xsl:variable>
          <xsl:variable name="conference_item">Conference Item</xsl:variable>
          <xsl:variable name="thesis">Thesis</xsl:variable>
          <xsl:variable name="journal_article">Journal Article</xsl:variable>
          <xsl:variable name="working_paper">Working Paper</xsl:variable>
          <xsl:variable name="reports">Report</xsl:variable>
          <xsl:variable name="other_resource">Other Resource</xsl:variable>
          <xsl:if test="$type = $book">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$type"/><xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printBook"/>
          </xsl:if>
          <xsl:if test="$type = $book_chapter">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/>Book Section<xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printBookChapter"/>
          </xsl:if>          
          <xsl:if test="$type = $conference_paper">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$type"/><xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printConferencePaper"/>
          </xsl:if>
          <xsl:if test="$type = $conference_item">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/>Conference Paper<xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printConferenceItem"/>
          </xsl:if>
          <xsl:if test="$type = $thesis">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$type"/><xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printThesis"/>
          </xsl:if>
          <xsl:if test="$type = $journal_article">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$type"/><xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printJournal"/>
          </xsl:if>
          <xsl:if test="$type = $working_paper">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/>Report<xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printWorkingPaper"/>
          </xsl:if>
          <xsl:if test="$type = $reports">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$type"/><xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printReports"/>
          </xsl:if>
          <xsl:if test="$type = $other_resource">
            <xsl:text>%0</xsl:text><xsl:value-of select="' '"/>Generic<xsl:text>&#10;</xsl:text>
            <xsl:call-template name="printOtherResource"/>
          </xsl:if>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
  
   <!-- printOtherResource -->  
  <xsl:template name="printOtherResource">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- print result out -->
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
  </xsl:template>
  
  <!-- printBook -->  
  <xsl:template name="printBook">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- edition -->
    <xsl:variable name="edition">
      <xsl:if test="marc:datafield[@tag='250' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='250' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publisher -->
    <xsl:variable name="publisher">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publication Place -->
    <xsl:variable name="place">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="editor">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2=' ' and @tag='700']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2=' ' and @tag='700']"/>
      </xsl:if>
    </xsl:variable>
    <!-- print result out -->
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($editor)) &gt; 0"><xsl:value-of select="$editor"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($edition)) &gt; 0"><xsl:text>%N</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$edition"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($publisher)) &gt; 0"><xsl:value-of select="$publisher"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($place)) &gt; 0"><xsl:value-of select="$place"/><xsl:text>&#10;</xsl:text></xsl:if>
  </xsl:template>

    <!-- Book Chapter -->  
  <xsl:template name="printBookChapter">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>  
    <!-- Title of the Chapter -->
    <xsl:variable name="chapter">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Book Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1=' ' and @ind2='0' and @tag='787']/marc:subfield[@code='t']">
        <xsl:apply-templates select="marc:datafield[@ind1=' ' and @ind2='0' and @tag='787']/marc:subfield[@code='t']"/>
      </xsl:if>
    </xsl:variable>
    <!-- edition -->
    <xsl:variable name="edition">
      <xsl:if test="marc:datafield[@tag='250' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='250' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publisher -->
    <xsl:variable name="publisher">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publication Place -->
    <xsl:variable name="place">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Page Number -->
    <xsl:variable name="page">
      <xsl:if test="marc:datafield[@ind1=' ' and @ind2='0' and @tag='787']/marc:subfield[@code='g']">
        <xsl:apply-templates select="marc:datafield[@ind1=' ' and @ind2='0' and @tag='787']/marc:subfield[@code='g']"/>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="editor">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2=' ' and @tag='700']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2=' ' and @tag='700']"/>
      </xsl:if>
    </xsl:variable>
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$chapter" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($editor)) &gt; 0"><xsl:value-of select="$editor"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($edition)) &gt; 0"><xsl:text>%N</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$edition"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($publisher)) &gt; 0"><xsl:value-of select="$publisher"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($place)) &gt; 0"><xsl:value-of select="$place"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($page)) &gt; 0"><xsl:value-of select="$page"/><xsl:text>&#10;</xsl:text></xsl:if>
  </xsl:template>
  
  <!-- Conference Paper -->  
  <xsl:template name="printConferencePaper">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title of published proceeding  -->
    <xsl:variable name="otherTitle">
      <xsl:if test="marc:datafield[@ind1='0' and @ind2=' ' and @tag='711']">
        <xsl:apply-templates select="marc:datafield[@ind1='0' and @ind2=' ' and @tag='711']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publisher -->
    <xsl:variable name="publisher">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publication Place -->
    <xsl:variable name="place">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Page Information -->
    <xsl:variable name="page">
      <xsl:if test="marc:datafield[@tag='787' and @ind1=' ' and @ind2='0']/marc:subfield[@code='g']">
        <xsl:apply-templates select="marc:datafield[@tag='787' and @ind1=' ' and @ind2='0']/marc:subfield[@code='g']"/>
      </xsl:if>
    </xsl:variable>
    
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($otherTitle)) &gt; 0"><xsl:value-of select="$otherTitle"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($publisher)) &gt; 0"><xsl:value-of select="$publisher"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($place)) &gt; 0"><xsl:value-of select="$place"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($page)) &gt; 0"><xsl:value-of select="$page"/><xsl:text>&#10;</xsl:text></xsl:if>
  </xsl:template>
  
  <!-- Conference Item -->  
  <xsl:template name="printConferenceItem">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Conferenc Information -->
    <xsl:variable name="confName">
      <xsl:if test="marc:datafield[@tag='787' and @ind1=' ' and @ind2='0']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='787' and @ind1=' ' and @ind2='0']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="confPlace">  
      <xsl:if test="marc:datafield[@ind1='0' and @ind2=' ' and @tag='711']/marc:subfield[@code='b']">
        <xsl:apply-templates select="marc:datafield[@ind1='0' and @ind2=' ' and @tag='711']/marc:subfield[@code='b']"/>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="confDate">
      <xsl:if test="marc:datafield[@ind1='0' and @ind2=' ' and @tag='711']/marc:subfield[@code='d']">
        <xsl:apply-templates select="marc:datafield[@ind1='0' and @ind2=' ' and @tag='711']/marc:subfield[@code='d']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publisher -->
    <xsl:variable name="publisher">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publication Place -->
    <xsl:variable name="place">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Page Information -->
    <xsl:variable name="page">
      <xsl:if test="marc:datafield[@tag='787' and @ind1=' ' and @ind2='0']/marc:subfield[@code='g']">
        <xsl:apply-templates select="marc:datafield[@tag='787' and @ind1=' ' and @ind2='0']/marc:subfield[@code='g']"/>
      </xsl:if>
    </xsl:variable>
    
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:text>%B</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$confName"/>
    <xsl:if test="string-length(normalize-space($confName)) &gt; 0"><xsl:value-of select="' '"/><xsl:value-of select="','"/></xsl:if>
    <xsl:value-of select="$confPlace"/>
    <xsl:if test="string-length(normalize-space($confPlace)) &gt; 0"><xsl:value-of select="' '"/><xsl:value-of select="','"/></xsl:if>
    <xsl:value-of select="$confDate"/><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($publisher)) &gt; 0"><xsl:value-of select="$publisher"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($place)) &gt; 0"><xsl:value-of select="$place"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($page)) &gt; 0"><xsl:value-of select="$page"/><xsl:text>&#10;</xsl:text></xsl:if>
  </xsl:template>
  
  <!-- Thesis -->  
  <xsl:template name="printThesis">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>    
    <!-- Award -->
    <xsl:variable name="award">
      <xsl:if test="marc:datafield[@tag='502' and @ind1='3' and @ind2=' ']/marc:subfield[@code='u']">
        <xsl:apply-templates select="marc:datafield[@tag='502' and @ind1='3' and @ind2=' ']/marc:subfield[@code='u']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Institution -->
    <xsl:variable name="place">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:call-template name="getThesisInst">
          <xsl:with-param name="arg0" select="marc:datafield[@tag='100']"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:variable>
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($award)) &gt; 0"><xsl:text>%9</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$award"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($place)) &gt; 0"><xsl:text>%I</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$place"/><xsl:text>&#10;</xsl:text></xsl:if>
  </xsl:template>

  <!-- Journal -->
  <xsl:template name="printJournal">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Journal Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Journal Name -->
    <xsl:variable name="name">
      <xsl:if test="marc:datafield[@tag='787' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='t']">
        <xsl:apply-templates select="marc:datafield[@tag='787' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='t']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Volume Number --> <!-- Issue Number --> <!-- Page Number -->
    <xsl:variable name="other">
      <xsl:if test="marc:datafield[@tag='787' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='g']">
        <xsl:call-template name="volumeIssuePage">
          <xsl:with-param name="arg0" select="marc:datafield[@tag='787' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='g']"/>
        </xsl:call-template>  
      </xsl:if>
    </xsl:variable>
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($name)) &gt; 0"><xsl:text>%B</xsl:text><xsl:value-of select="' '" /><xsl:value-of select="$name" /><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:value-of select="$other" />
  </xsl:template>
  
  <!-- Working Paper -->  
  <xsl:template name="printWorkingPaper">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- SERIES -->
    <xsl:variable name="series">
      <xsl:if test="marc:datafield[@tag='830' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='v']">
        <xsl:apply-templates select="marc:datafield[@tag='830' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='v']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publisher -->
    <xsl:variable name="publisher">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publication Place -->
    <xsl:variable name="place">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($series)) &gt; 0"><xsl:text>%Z</xsl:text><xsl:value-of select="' '"/>Series<xsl:value-of select="' '"/>in<xsl:value-of select="' '"/><xsl:value-of select="$series"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($publisher)) &gt; 0"><xsl:value-of select="$publisher"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($place)) &gt; 0"><xsl:value-of select="$place"/><xsl:text>&#10;</xsl:text></xsl:if>
  </xsl:template>
  
  <!-- Reports -->
  <xsl:template name="printReports">
    <!-- Author -->
    <xsl:variable name="author">
      <xsl:if test="marc:datafield[@tag='100']">
        <xsl:apply-templates select="marc:datafield[@tag='100']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Year -->
    <xsl:variable name="year">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Title -->
    <xsl:variable name="title">
      <xsl:if test="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
        <xsl:apply-templates select="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publisher -->
    <xsl:variable name="publisher">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']"/>
      </xsl:if>
    </xsl:variable>
    <!-- Publication Place -->
    <xsl:variable name="place">
      <xsl:if test="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
        <xsl:apply-templates select="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']"/>
      </xsl:if>
    </xsl:variable>
    <xsl:value-of select="$author" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$year" /><xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$title" /><xsl:text>&#10;</xsl:text>
    <xsl:if test="string-length(normalize-space($publisher)) &gt; 0"><xsl:value-of select="$publisher"/><xsl:text>&#10;</xsl:text></xsl:if>
    <xsl:if test="string-length(normalize-space($place)) &gt; 0"><xsl:value-of select="$place"/><xsl:text>&#10;</xsl:text></xsl:if>
  </xsl:template>
  
  <!-- Author Information -->
  <xsl:template match="marc:datafield[@tag='100']">
    <xsl:variable name="pointer" select="position()" />
    <xsl:variable name="total" select="last()" />
    <xsl:choose>
      <xsl:when test="subfield[@code='a']">
        <xsl:call-template name="getAuthor">
          <xsl:with-param name="arg0" select="subfield[@code='a']"/>
        </xsl:call-template>
        <xsl:if test="$pointer = $total">
        </xsl:if>
        <xsl:if test="$pointer != $total"><xsl:text>&#10;</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:when test="marc:subfield[@code='a']">
        <xsl:call-template name="getAuthor">
          <xsl:with-param name="arg0" select="marc:subfield[@code='a']"/>
        </xsl:call-template>
        <xsl:if test="$pointer = $total">
        </xsl:if>
        <xsl:if test="$pointer != $total"><xsl:text>&#10;</xsl:text>
        </xsl:if>        
      </xsl:when>
    </xsl:choose>  
  </xsl:template>
  
  <!-- Year -->  
  <xsl:template match="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='c']">
    <xsl:text>%D</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="."/>
  </xsl:template>
  
  <!-- Title -->
  <xsl:template match="marc:datafield[@ind1='1' and @ind2='0' and @tag='245']">
    <xsl:text>%T</xsl:text><xsl:value-of select="' '"/>
    <xsl:choose>
      <xsl:when test="marc:subfield[@code='a']">
        <xsl:value-of select="marc:subfield[@code='a']"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
  
  <!-- Top Title -->
  <xsl:template match="marc:datafield[@ind1=' ' and @ind2='0' and @tag='787']/marc:subfield[@code='t']">
    <xsl:text>%B</xsl:text><xsl:value-of select="' '"/>
    <xsl:value-of select="."/>
  </xsl:template>

  <!-- Book Page Number -->
  <xsl:template match="marc:datafield[@ind1=' ' and @ind2='0' and @tag='787']/marc:subfield[@code='g']">
    <xsl:text>%P</xsl:text><xsl:value-of select="' '"/>
    <xsl:variable name="delimiter" select="'.'"/>
    <xsl:variable name="page" select="."/>
    <xsl:choose>
      <xsl:when test="contains($page, $delimiter)"><xsl:value-of select="substring-after($page, $delimiter)"/></xsl:when>
      <xsl:otherwise><xsl:value-of select="$page"/></xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <!-- Editor -->
  <xsl:template match="marc:datafield[@ind1='1' and @ind2=' ' and @tag='700']">
    <xsl:variable name="pointer" select="position()" />
    <xsl:variable name="total" select="last()" />
    <xsl:variable name="editorC">Editor</xsl:variable>
    <xsl:if test="marc:subfield[@code='e']">
      <xsl:variable name="editorV" select="marc:subfield[@code='e']"/>
      <xsl:if test="$editorV = $editorC">
        <xsl:text>%E</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="marc:subfield[@code='a']"/>
      </xsl:if>
      <xsl:if test="$pointer = $total"/>
      <xsl:if test="$pointer != $total"><xsl:text>&#10;</xsl:text>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  
  <!-- Publisher -->
  <xsl:template match="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='b']">
    <xsl:text>%I</xsl:text><xsl:value-of select="' '"/>
    <xsl:value-of select="."/>
  </xsl:template>  

  <!-- Publication Place -->
  <xsl:template match="marc:datafield[@tag='260' and @ind1=' ' and @ind2=' ']/marc:subfield[@code='a']">
    <xsl:text>%C</xsl:text><xsl:value-of select="' '"/>
    <xsl:value-of select="."/>
  </xsl:template>
  
  <!-- Conference Publication Information -->
  <xsl:template match="marc:datafield[@ind1='0' and @ind2=' ' and @tag='711']">
    <xsl:text>%B</xsl:text><xsl:value-of select="' '"/>
    <xsl:if test="marc:subfield[@code='t']"><xsl:value-of select="marc:subfield[@code='t']" /></xsl:if><xsl:if test="marc:subfield[@code='c']">,<xsl:value-of select="' '"/><xsl:value-of select="marc:subfield[@code='c']" /></xsl:if><xsl:if test="marc:subfield[@code='d']">,<xsl:value-of select="' '"/><xsl:value-of select="marc:subfield[@code='d']" /></xsl:if>
  </xsl:template>
  
  <!-- xsl functions -->
  <xsl:template name='getThesisInst'>
    <xsl:param name="arg0"/>
    <xsl:variable name="delimiter" select="', '" />
    <xsl:variable name="afterString" select="substring-after($arg0, $delimiter)" />
    <xsl:value-of select="substring-after($afterString, $delimiter)"/>
  </xsl:template>
  
  <xsl:template name='getAuthor'>
    <xsl:param name="arg0"/>
    <xsl:variable name="delimiter" select="', '" />
    <xsl:variable name="beforeString" select="substring-before($arg0, $delimiter)" />
    <xsl:variable name="afterString" select="substring-after($arg0, $delimiter)" />
    <xsl:choose>
      <xsl:when test="contains($afterString, $delimiter)">
        <xsl:call-template name="authorName">
          <xsl:with-param name="arg0" select="normalize-space($arg0)"/>
          <xsl:with-param name="removeString" select="true()"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="authorName">
          <xsl:with-param name="arg0" select="normalize-space($arg0)"/>
          <xsl:with-param name="removeString" select="false()"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template name='authorName'>
    <xsl:param name="arg0"/>
    <xsl:param name="removeString"/>
    <xsl:variable name="delimiter">,</xsl:variable>
    <xsl:choose>
      <xsl:when test="$removeString = false()">
        <xsl:text>%A</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="normalize-space($arg0)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="lastName" select="substring-before(normalize-space($arg0), $delimiter)"/>
        <xsl:variable name="otherNames" select="substring-before(substring-after(normalize-space($arg0), $delimiter), $delimiter)"/>
        <xsl:text>%A</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="$lastName"/>, <xsl:value-of select="normalize-space($otherNames)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template name="volumeIssuePage">
    <xsl:param name="arg0"/>
    <xsl:variable name="delimiter" select="';'" />
    <xsl:variable name="colon" select="':'" />
    <xsl:variable name="dot" select="'.'" />
    <xsl:variable name="volText">Vol:</xsl:variable>
    <xsl:variable name="issText">Issue:</xsl:variable>
    <xsl:variable name="ppText">pp.</xsl:variable>
    <xsl:if test="contains($arg0, $volText)" ><xsl:text>%V</xsl:text><xsl:value-of select="' '"/>
		<xsl:choose>
		<xsl:when test="contains(substring-after($arg0, $volText), $delimiter)"><xsl:value-of select="substring-before(substring-after($arg0, $volText), $delimiter)" /><xsl:text>&#10;</xsl:text></xsl:when>
		<xsl:otherwise><xsl:value-of select="substring-after($arg0, $volText)" /><xsl:text>&#10;</xsl:text></xsl:otherwise>
		</xsl:choose>
	</xsl:if>
    <xsl:if test="contains($arg0, $issText)" ><xsl:text>%N</xsl:text><xsl:value-of select="' '"/>
		<xsl:choose>
		<xsl:when test="contains(substring-after($arg0, $issText), $delimiter)"><xsl:value-of select="substring-before(substring-after($arg0, $issText), $delimiter)" /><xsl:text>&#10;</xsl:text></xsl:when>
		<xsl:otherwise><xsl:value-of select="substring-after($arg0, $issText)" /><xsl:text>&#10;</xsl:text></xsl:otherwise>
		</xsl:choose>
	</xsl:if>
    <xsl:if test="contains($arg0, $ppText)" ><xsl:text>%P</xsl:text><xsl:value-of select="' '"/><xsl:value-of select="substring-after($arg0, $ppText)" /><xsl:text>&#10;</xsl:text></xsl:if>  
  </xsl:template>
  
</xsl:stylesheet>